<?php

class Mailer {

    public static function sendMail($to, $subject, $message, $from = MAIL_FROM, $section = NULL) {

        $headers  = 'MIME-Version: 1.0' . "\r\n";
        $headers .= 'Content-type: text/plain; charset=utf-8' . "\r\n";
        $headers .= "From: $from" . "\r\n";
        $headers .= "Reply-To: info@musdb.net" . "\r\n";

        $result = mail($to, $subject, $message, $headers);

        $dbo = DBO::getInstance();

        $dbo->query('INSERT INTO sys.mail_log
            ("to", "subject", "message", "from", "result", section)
            VALUES (?,?,?,?,?,?)',
            array(
                DBString::create($to),
                DBString::create($subject),
                DBString::create($message),
                DBString::create($from),
                DBBoolean::create($result),
                DBString::create($section)
            ));       

        return $result;
    }
}